package copyengine.utils
{
	import copyengine.utils.debug.CELog;

	public final class CEActorDirUtils
	{
		public static const DIR_LEFT:int = 1;
		public static const DIR_RIGHT:int = 2;
		public static const DIR_UP:int = 3;
		public static const DIR_DOWN:int = 4;

		public static const DIR_UP_LEFT:int = 11;
		public static const DIR_UP_RIGHT:int = 12;
		public static const DIR_DOWN_LEFT:int = 13;
		public static const DIR_DOWN_RIGHT:int = 14;

		public function CEActorDirUtils()
		{
		}

		/**
		 * 判断两个方向是否是在同一个十字坐标系中
		 * 上下左右是一个十字坐标
		 * 斜上斜下斜左斜右又是一个十字坐标
		 */
		public static function isUnderSameCrossDir(_dirA:int, _dirB:int):Boolean
		{
			return Math.abs(_dirA - _dirB) <= 3;
		}

		public static function getActorDir(_prePosX:int, _prePosY:int, _currentPosX:int, _currentPosY:int):int
		{
			if (_currentPosX - _prePosX > 0)
			{
				if (_currentPosY - _prePosY > 0)
				{
					return DIR_DOWN_RIGHT;
				}
				else if (_currentPosY - _prePosY < 0)
				{
					return DIR_UP_RIGHT;
				}
				else
				{
					return DIR_RIGHT;
				}
			}
			else if (_currentPosX - _prePosX < 0)
			{
				if (_currentPosY - _prePosY > 0)
				{
					return DIR_DOWN_LEFT;
				}
				else if (_currentPosY - _prePosY < 0)
				{
					return DIR_UP_LEFT;
				}
				else
				{
					return DIR_LEFT;
				}
			}
			else
			{
				if (_currentPosY - _prePosY > 0)
				{
					return DIR_DOWN;
				}
				else if (_currentPosY - _prePosY < 0)
				{
					return DIR_UP;
				}
				else
				{
					CELog.err("CEActorDirUtils->getActorDir currentPos and prePos as same");
					return 0;
				}
			}
		}

	}
}
